{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('resource/english.csv')\n",
    "def read_unmach_word():\n",
    "    unmach_idx = [index for index,val in df['state'].items() if val == 0] #list\n",
    "    unmach_word = [(idx, val) for idx,val in df['word'][unmach_idx].items()] #List [(idx, word)]\n",
    "    return unmach_word\n",
    "def update():\n",
    "    unmach_word = read_unmach_word()\n",
    "    for x in unmach_word:\n",
    "        sentens = get_sentens(x[1])\n",
    "        df.loc[x[0]:x[0], 'sentence'] = sentens\n",
    "        df.loc[x[0]:x[0], 'state'] = sentens = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_sentens(word):\n",
    "    f = open('resource/db/spring.txt')\n",
    "    cotent_l = f.read().split('\\n')\n",
    "    sentens_l = [sentens for sentens in cotent_l if word in sentens]     \n",
    "    return sentens_l[0] if len(sentens_l)>0 else ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>word</th>\n",
       "      <th>sentence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>trival</td>\n",
       "      <td>test1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>iteration</td>\n",
       "      <td>test1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>apple</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>implicit</td>\n",
       "      <td>test1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>Spring</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   state       word sentence\n",
       "0      0     trival    test1\n",
       "1      0  iteration    test1\n",
       "2      0      apple      NaN\n",
       "3      0   implicit    test1\n",
       "4      0     Spring      NaN"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "print(df.loc[0:0,('sentence', 'state')])\n",
    "print(type(df.loc[0:0,('sentence', 'state')]))\n",
    "df.loc[0:0,'sentence'] = 't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   state       word                                           sentence\n",
      "0      1     trival                                                   \n",
      "1      1  iteration                                                   \n",
      "2      1      apple                                                   \n",
      "3      1   implicit  At this point, you could import the project in...\n",
      "4      1     Spring                Spring Boot Reference Documentation\n"
     ]
    }
   ],
   "source": [
    "update()\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('resource/english.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".txt\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "dir = 'resource/db/'\n",
    "l = os.listdir(dir)\n",
    "type(l[0])\n",
    "root, extent = os.path.splitext(l[0])\n",
    "print(extent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
